<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/1/24
  Time: 13:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<p>
    <form action="/find" method="post">
        类型:
        <select name="typeId">
            <option value="-1">不限</option>
            <c:forEach items="${billTypes}" var="bt">
                <option value="${bt.id}" ${typeId==bt.id?"selected":""} >${bt.name}</option>
            </c:forEach>
        </select>
        时间：从<input type="text" name="fromDate" value="${fromDate}">
        到<input type="text" name="toDate" value="${toDate}">
        <input type="submit" value="搜索">
    </form>
</p>
<button onclick="javascript:location.href='/getTypes'">记账</button>
<table border="1" width="600">
    <tr>
        <td>标题</td>
        <td>时间</td>
        <td>类别</td>
        <td>金额</td>
        <td>说明</td>
        <td>操作</td>
    </tr>
    <c:if test="${billsPageInfo.list.size()!=0}">
        <c:forEach items="${billsPageInfo.list}" var="bill">
            <tr>
                <td>${bill.title}</td>
                <td><fmt:formatDate value="${bill.billtime}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                <td>${bill.billType.name}</td>
                <td>
                    <c:choose>
                        <c:when test="${bill.billType.name == '支出' || bill.billType.name == '借出' || bill.billType.name == '还出'}">
                            -${bill.price}
                        </c:when>
                        <c:when test="${bill.billType.name == '收入' || bill.billType.name == '借入' || bill.billType.name == '还入'}">
                            +${bill.price}
                        </c:when>
                        <c:otherwise>
                            ${bill.price}
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>${bill.billexplain}</td>
                <td>
                    <a href="/findByBillId?billid=${bill.id}">修改</a>
                    <a href="/deleteById?billid=${bill.id}">删除</a>
                </td>
            </tr>
        </c:forEach>
    </c:if>
    <c:if test="${billsPageInfo.list.size()==0}">
        <tr>
            <td colspan="6"><h3>没有找到数据</h3></td>
        </tr>
    </c:if>
    <tr>
        <td colspan="6">
            <a href="/find?index=1&typeId=${typeId}&fromDate=${fromDate}&toDate=${toDate}">首页</a>

            <a href="/find?index=${billsPageInfo.prePage==0?1:billsPageInfo.prePage}&typeId=${typeId}&fromDate=${fromDate}&toDate=${toDate}">上一页</a>

            <a href="/find?index=${billsPageInfo.nextPage==0?billsPageInfo.pages:billsPageInfo.nextPage}&typeId=${typeId}&fromDate=${fromDate}&toDate=${toDate}">下一页</a>

            <a href="/find?index=${billsPageInfo.pages}&typeId=${typeId}&fromDate=${fromDate}&toDate=${toDate}">尾页</a>

            总页数:${billsPageInfo.pages}

            总条数:${billsPageInfo.total}
        </td>
    </tr>
</table>

</body>
</html>
